require 'find'

class TestController < ApplicationController

  include Test
  def index
    @filenames=[]
    @basefolder ="#{Rails.root}/public"
    Find.find(@basefolder) do |f|
    # p f if File.basename(f) =~ /.*\.txt$/
      unless File.directory?f
      @filenames << f
      end
    end
  end

  def downfile
    filepath = params[:filename]
    send_file filepath, :disposition => 'attachment'
  end

  def filedownload1
    # downloadFile
    getFile

  end

  def  filedownload
    Net::HTTP.start("127.0.0.1","8080") { |http|
      @resp = http.get("/a/FidelityMain.apk")
      send_data @resp.body,:disposition => 'inline',:filename => "hahah"
    }

  end

  def downloadlocal
    send_file "/public/files/"+ params[:filename] unless params[:filename].blank?
    render :nothing => true
  end

  def testrequest
    content_type = request.headers["Content-Type"]
    method = request.request_method
    @from = request.remote_ip
    # render :text => method + "from " + from
    session[:from] =@from
    redirect_to   :action => "display"  ,:id => "hhd"
  end

  def baidu
    headers["Status"] ="301 moved permanentlyddd"
    redirect_to "http://www.baidu.com"
  end

  def display
    @from = request.remote_ip
    @title = "myheader"
  end
end
